package cn.edu.sgu.www.mhxysy.service.children.impl;

import cn.edu.sgu.www.mhxysy.entity.children.Children;
import cn.edu.sgu.www.mhxysy.entity.children.ChildrenViewZizhi;
import cn.edu.sgu.www.mhxysy.mapper.children.ChildrenMapper;
import cn.edu.sgu.www.mhxysy.mapper.children.ChildrenViewZizhiMapper;
import cn.edu.sgu.www.mhxysy.service.children.ChildrenViewZizhiService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class ChildrenViewZizhiServiceImpl implements ChildrenViewZizhiService {

    private final ChildrenMapper childrenMapper;
    private final ChildrenViewZizhiMapper childrenViewZizhiMapper;

    @Autowired
    public ChildrenViewZizhiServiceImpl(
            ChildrenMapper childrenMapper,
            ChildrenViewZizhiMapper childrenViewZizhiMapper) {
        this.childrenMapper = childrenMapper;
        this.childrenViewZizhiMapper = childrenViewZizhiMapper;
    }

    @Override
    public ChildrenViewZizhi selectByChildrenId(String childrenId) {
        // 查询子女信息
        Children children = childrenMapper.selectById(childrenId);

        // 根据子女提升次数查询子女预览资质
        QueryWrapper<ChildrenViewZizhi> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq("type", 1);
        queryWrapper.eq("improve_times", children.getImproveTimes());

        return childrenViewZizhiMapper.selectOne(queryWrapper);
    }

}